<?php
if(!check_manager_login()) exit('无权查看，<a href="index.php">请登录!</a>');
require_once(MODEL_PATH.DS.'AttributeValue.php');
require_once(MODEL_PATH.DS.'Category.php');
require_once(MODEL_PATH.DS.'Brand.php');
require_once(MODEL_PATH.DS.'Product.php');
require_once(MODEL_PATH.DS.'ProductDesc.php');
require_once(MODEL_PATH.DS.'ProductAttribute.php');
require_once(MODEL_PATH.DS.'ProductTag.php');
require_once(MODEL_PATH.DS.'ProductImage.php');
require_once(MODEL_PATH.DS.'ProductCategory.php');
$ProductAttribute = new ProductAttribute();
$Product = new Product();
$ProductCategory = new ProductCategory();
$ProductDesc = new ProductDesc();
$ProductTag = new ProductTag();
$ProductImage = new ProductImage();
$product_id = (int)$_GET['product_id'];

$p_info = $Product->getProductDetailById($product_id);
if($p_info){
	if(file_exists(PRODUCT_IMAGES.$p_info['product_img'])){
		@unlink(PRODUCT_IMAGES.$p_info['product_img']);
	}
	if(file_exists(PRODUCT_IMAGES.$p_info['product_thumb'])){
		@unlink(PRODUCT_IMAGES.$p_info['product_thumb']);
	}
}

$result = $Product->delProductById($product_id);

$result = $ProductAttribute->delPAbyPid($product_id);

$result = $ProductCategory->delPCByPid($product_id);

$result = $ProductDesc->delProductDescByPid($product_id);

$result = $ProductTag->delTagByPid($product_id);

$product_image_arr = $ProductImage->getProductImgByPid($product_id);
if($product_image_arr){
	foreach($product_image_arr as $img){
		if(file_exists(PRODUCT_IMAGES.$img['image'])){
			unlink(PRODUCT_IMAGES.$img['image']);
		}
	}
}
$result = $ProductImage->delProductImgByPid($product_id);

if($result) redirect('index.php?mod=product&act=list','删除产品成功！');
